package com.itjeffrey.autocode.controller;

import com.itjeffrey.autocode.bo.ScheduleJobBO;
import com.itjeffrey.autocode.common.Result;
import com.itjeffrey.autocode.service.ScheduleJobTbService;
import io.swagger.models.auth.In;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 控制器类
 * @author: admin
 * @date: 2021-04-17 01:03:13
 */
@RestController
@RequestMapping("/schedule/job")
public class ScheduleJobTbController {

    @Resource
    private ScheduleJobTbService scheduleJobTbService;

    /**
     * 新增任务
     * @param scheduleJobBO
     * @return
     */
    @PostMapping("/add")
    public ResponseEntity<Result> add(@RequestBody ScheduleJobBO scheduleJobBO){
        return ResponseEntity.ok(scheduleJobTbService.add(scheduleJobBO));
    }

    /**
     * 修改任务
     * @param scheduleJobBO
     * @return
     */
    @PostMapping("/mod")
    public ResponseEntity<Result> mod(@RequestBody ScheduleJobBO scheduleJobBO){
        return ResponseEntity.ok(scheduleJobTbService.mod(scheduleJobBO));
    }

    /**
     * 删除任务
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    public ResponseEntity<Result> delete(@PathVariable("id") Integer id){
        return ResponseEntity.ok(scheduleJobTbService.deleteById(id));
    }

    /**
     * 暂停任务
     * @param id
     * @return
     */
    @PostMapping("/pauseJob/{id}")
    public ResponseEntity<Result> pauseJob(@PathVariable("id") String id){
        return ResponseEntity.ok(scheduleJobTbService.pauseJob(id));
    }

    /**
     * 恢复任务
     * @param id
     * @return
     */
    @PostMapping("/resumeJob/{id}")
    public ResponseEntity<Result> resumeJob(@PathVariable("id") String id){
        return ResponseEntity.ok(scheduleJobTbService.resumeJob(id));
    }

    /**
     * 查询任务详情
     * @param id
     * @return
     */
    @PostMapping("/query/{id}")
    public ResponseEntity<Result> queryById(@PathVariable("id") Integer id){
        return ResponseEntity.ok(scheduleJobTbService.queryById(id));
    }

    /**
     * 查询任务列表
     * @param scheduleJobBO
     * @return
     */
    @PostMapping("/queryList")
    public ResponseEntity<Result> queryList(@RequestBody ScheduleJobBO scheduleJobBO){
        return ResponseEntity.ok(scheduleJobTbService.queryList(scheduleJobBO));
    }

    /**
     * 获取任务ID
     * @param
     * @return
     */
    @PostMapping("/getJobId")
    public ResponseEntity<Result> getJobId(){
        return ResponseEntity.ok(scheduleJobTbService.getJobId());
    }

}